import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class Utils {
  /// 第三方控件配置
  static Widget customHeader = const ClassicHeader(
    releaseText: "松开刷新",
    refreshingText: "正在刷新",
    completeText: "刷新完成",
    failedText: "刷新失败",
    idleText: "下拉刷新",
  );

  static Widget customFooter = const ClassicFooter(
    loadingText: "正在加载",
    noDataText: "━━━━━━━━━ 我也是有底线的 ━━━━━━━━━",
    idleText: "上拉加载",
    failedText: "加载失败",
    canLoadingText: "松开加载",
  );

  static String converDoubleToString(double? value) {
    if (value is double) {
      String doubleString = value.toStringAsFixed(2);
      String sub1 = doubleString.substring(
        doubleString.length - 1,
        doubleString.length,
      );
      if (sub1 == "0") {
        doubleString = doubleString.substring(0, doubleString.length - 1);
        String sub2 = doubleString.substring(
          doubleString.length - 1,
          doubleString.length,
        );
        if (sub2 == "0") {
          doubleString = doubleString.substring(0, doubleString.length - 2);
        }
      }

      return doubleString;
    }
    return "0";
  }
}

class MyLocale implements DateLocale {
  const MyLocale();

  @override
  final List<String> monthsShort = const [
    'Jan',
    'Feb',
    'Mar',
    'Apr',
    'May',
    'Jun',
    'Jul',
    'Aug',
    'Sep',
    'Oct',
    'Nov',
    'Dec'
  ];

  @override
  final List<String> monthsLong = const [
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December'
  ];

  @override
  final List<String> daysShort = const [
    '周一',
    '周二',
    '周三',
    '周四',
    '周五',
    '周六',
    '周日'
  ];

  @override
  final List<String> daysLong = const [
    '星期一',
    '星期二',
    '星期三',
    '星期四',
    '星期五',
    '星期六',
    '星期天'
  ];

  @override
  String get am => "AM";

  @override
  String get pm => "PM";
}

Color progressColor(double progress, {int type = 1}) {
  if (progress >= 0.8) {
    return const Color(0xFF49A078);
  } else if (progress >= 0.6) {
    return const Color(0xFFF8CB4E);
  } else if (progress > 0) {
    return const Color(0xFFDA5552);
  } else {
    if (type == 1) {
      return const Color(0xFFF2F2F2);
    } else {
      return const Color(0xFF656565);
    }
  }
}

class MyScrollBehavior extends ScrollBehavior {
  // @override
  // Widget buildViewportChrome(
  //     BuildContext context, Widget child, AxisDirection axisDirection) {
  //   return GlowingOverscrollIndicator(
  //     axisDirection: axisDirection,
  //     color: Colors.transparent,
  //     showLeading: false,
  //     showTrailing: false,
  //     child: child,
  //   );
  // }

  @override
  ScrollPhysics getScrollPhysics(BuildContext context) {
    return const ClampingScrollPhysics();
  }

  @override
  Widget buildOverscrollIndicator(
      BuildContext context, Widget child, ScrollableDetails details) {
    return child;
  }
}

class GlobalRefresh {
  static bool taskViewNeedRefresh = false;
  static bool checkViewNeedRefresh = false;
}

///虚线1
class DashedLineWidget1 extends StatelessWidget {
  final Axis axis; //方向:水平或垂直
  final double dasWidth; //线的宽度
  final double dasHeight; //线的高度
  final Color dasColor; //线的颜色
  final double intervalWidth; //间隔的宽度

  const DashedLineWidget1(
      {required this.axis,
      required this.dasWidth,
      required this.dasHeight,
      required this.dasColor,
      required this.intervalWidth,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        final boxWidth = constraints.constrainWidth(); // 容器的宽度
        final dashCount = (boxWidth / (2 * dasWidth)).floor(); //个数
        return Flex(
          direction: axis,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: List.generate(dashCount, (_) {
            return SizedBox(
              width: dasWidth,
              height: dasHeight,
              child: DecoratedBox(
                decoration: BoxDecoration(
                  color: dasColor,
                ),
              ),
            );
          }),
        );
      },
    );
  }
}
